﻿using System.Collections.Generic;
using System.Linq;
using DAL;

namespace BLL
{
    public class TeacherBll
    {
        private readonly Teacher _teacher;
        
        public TeacherBll(int id)
        {
            using (var context = new ModelContainer())
            {
                _teacher = context.Teachers
                    .Include("Courses")
                    .Include("Courses.CourseInfo")
                    .SingleOrDefault(teacher => teacher.ID == id);
            }
        }

        public Teacher GetTeacher()
        {
            return _teacher;
        }

        public List<Teacher> GetSameNameTeachers()
        {
            using (var context = new ModelContainer())
            {
                var targetTeachers = from anyTeachers in context.Teachers
                                     where anyTeachers.TeacherName.CompareTo(_teacher.TeacherName) == 0
                                           && anyTeachers.ID != _teacher.ID 
                                     select anyTeachers;
                return targetTeachers.ToList();
            }
        }

        public List<Course> GetTaughtCourses()
        {
            return _teacher.Courses.ToList();
        }
    }
}
